package terra;

import java.io.File;
import java.lang.reflect.Field;

import org.newdawn.slick.SlickException;

import terra.managers.DefManager;
import terra.managers.MapManager;
import terra.managers.ThreadPoolManager;
import terra.network.PlayerHandler;
public class Loader {

	public static Thread nettyThread;
	public static PlayerHandler handler;
	
	public static void main(String[] args){
		prepareSystem();
		init();
		try {
			Game.create();
		} catch (SlickException e) {
			e.printStackTrace();
		}
	}
	public static void init(){
		Config.loadConfig();
		ThreadPoolManager.getInstance();
		DefManager.init();
		MapManager.getInstance();
		BootStrap.load(BootStrap.CLIENT_MODE, PlayerHandler.class);
	}

	static void prepareSystem()
	{
		File f = new File("");
		try	{
			System.setProperty( "java.class.path", f.getAbsolutePath()+File.separator+"lib"+File.separator );
			if (System.getProperties().getProperty("os.name").contains("Windows"))
				System.setProperty( "java.library.path", f.getAbsolutePath()+File.separator+"native"+File.separator+"win"+File.separator);
			else if (System.getProperties().getProperty("os.name").contains("Mac"))
				System.setProperty( "java.library.path", f.getAbsolutePath()+File.separator+"native"+File.separator+"mac"+File.separator);		
			else 
				System.setProperty( "java.library.path", f.getAbsolutePath()+File.separator+"native"+File.separator+"lin"+File.separator);
			System.out.println(System.getProperties().get("java.library.path"));
			System.out.println(System.getProperties().get("java.class.path"));
			Field fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" );
			fieldSysPath.setAccessible( true );
			fieldSysPath.set( null, null );
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}
